import java.io.*;
import java.util.*;

public class ConfigParser {
    /**
     * The properties object to load the properties file into.
     */
    private Properties prop;

    public ConfigParser() {
	this.readConfig();
    }

    /**
     * Reads the config.properties file to be used for future parsing.
     */
    public void readConfig() {
	this.prop = new Properties();
	try {
	    this.prop.load(new FileInputStream("config.properties"));
	    //System.out.println(this.prop.toString());
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }

    /**
     * Returns an array of neighbors for the given peer_ip.
     */
    public String[] getNeighbors(String peer_ip) {
	String[] peers = {"NA"};

	try {
	    String neighbors = this.prop.getProperty(peer_ip);
	    if(neighbors != null) {
		peers = neighbors.split(",");
	    }
	} catch(Exception e) {
	    e.printStackTrace();
	}
		
	return peers;
    }

    /*
    public static void main(String args[]) {
	ConfigParser obj = new ConfigParser();	
	System.out.println(obj.getNeighbors("216.47.152.98"));
    }
    */
}